$(document).ready(function () {
		
	var vars = [], hash;
      var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('#');
	    for(var i = 0; i < hashes.length; i++) {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
     var user = vars["user"];
     var localizacion;
	$('#map').gmap('getCurrentPosition', function(position, status) {
			if ( status === 'OK' ) {
			localizacion = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
			
			}
		});
		
	$("#botonComparte").click(function(e) { 
		
	
			var titulo = $(".titulo").val();
			var texto = $(".texto").val();
			if(titulo == "Add titulo"){
				$(".titulo").focus().after("<span class='error'>Ingress a title</span>");
	            return false;
	         }
	         if(texto == ""){
	         	$(".texto").focus().after("<span class='error'>Ingress a Text</span>");
	            return false;
	         }    
			
		var Comentario = Parse.Object.extend("Comentarios");
		var coment = new Comentario();
		Parse.$= jQuery; 
		 //Parse.initialize("cIsgepqAZm90F2mWdiJ9nP5HkrdG3nBcs98yJrVA", "CYI3htcqoz9bERjSCTpqu5FOWjhkkl72CgEenoLD");	
		Parse.initialize("UCyMTCIXJqmFk3oLy4CwkxXv6oymztzqqoQNWAux", "BBYPhajAwBgLFzDTXvnx4MaReUn8Kke2KkwQ4yTT");
		//Parse.initialize("gLxhWhhBK7SPLZ7Jevs6q2lcLBlhje3l3sQlyS0e", "nPvJsuTXpFeKvNyDjZg8ks8sYwt2nntVOi9hr91J");
		coment.set("usuario", user);
		coment.set("title", titulo);
		coment.set("texto", texto);
		coment.save();
		actualizaLoc();
		
		document.location.href='home.html?user='+user+'#share';

	});
	
	function actualizaLoc(){
		Parse.$= jQuery; 
		 //Parse.initialize("cIsgepqAZm90F2mWdiJ9nP5HkrdG3nBcs98yJrVA", "CYI3htcqoz9bERjSCTpqu5FOWjhkkl72CgEenoLD");	
		Parse.initialize("UCyMTCIXJqmFk3oLy4CwkxXv6oymztzqqoQNWAux", "BBYPhajAwBgLFzDTXvnx4MaReUn8Kke2KkwQ4yTT");
		//Parse.initialize("gLxhWhhBK7SPLZ7Jevs6q2lcLBlhje3l3sQlyS0e", "nPvJsuTXpFeKvNyDjZg8ks8sYwt2nntVOi9hr91J");
		var Prueba2 = Parse.Object.extend("Friends");
		var query = new Parse.Query(Prueba2);
    // ckessler is the current user
    	query.equalTo("friend2", user);
   	 	query.find({
      		success: function(results) {
        		$.each(results, function(i,result){
            		result.save(null, {
              			success: function(result) {
                			result.set("lat", localizacion.lat());
                			result.set("lng", localizacion.lng());
                			result.save();
              			}
            		});

        		});  

      		}
    	});
		}
	
	
	
	
	
	
	
});